package com.catazy.module_home.repository

import com.catazy.module_home.bean.ArticleData
import com.catazy.module_home.bean.ArticleDetail
import com.catazy.wanandroid.common_base.bean.HttpResult
import com.catazy.wanandroid.common_service.banner.bean.Banner
import dagger.hilt.android.scopes.ActivityRetainedScoped
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

/**
 * 作者: Tao
 * 日期: 2024/5/6
 * 时间: 11:07
 * 描述: 首页数据仓库
 */
@ActivityRetainedScoped
class HomeRepository @Inject constructor(
    private val remoteRepository: HomeRemoteRepository,
    private val localRepository: HomeLocalRepository
) {

    fun getTopArticles(): Flow<HttpResult<List<ArticleDetail>>> {
        return remoteRepository.getTopArticles()
    }

    fun getArticles(pageNum: Int): Flow<HttpResult<ArticleData>> {
        return remoteRepository.getArticles(pageNum)
    }

    fun getBanners(): Flow<HttpResult<List<Banner>>> {
        return remoteRepository.getBanners()
    }

    fun insertBanners(banners: List<Banner>) {
        localRepository.insertBanners(banners)
    }
}